﻿using B.S.DataBase.MyProject.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T.E.ERP.Write.API.Applicantions.Command.CientsCommand;
using T.E.ERP.Write.API.Applicantions.Command.InvoicesandCommand;
using T.E.ERP.Write.API.Applicantions.CommandHandler.InvoicesandCommandHandler;

namespace T.E.ERP.Write.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ClientsManagementController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ClientsManagementController> logger;

        public ClientsManagementController(IMediator mediator, ILogger<ClientsManagementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 客户档案新增
        /// </summary>
        /// <param name="command">实体</param>
        /// <returns>int</returns>
        [HttpPost]
        public async Task<APIResult<object>> AddClientfunc(AddClientsCommand command)
        {
            try
            {
                logger.LogInformation(DateTime.Now + "调用客户档案新增方法成功");
            }
            catch (Exception ex)
            {
                logger.LogInformation(DateTime.Now + "调用客户档案新增方法失败" + ex.Message);
            }
            return await mediator.Send(command);
        }
        /// <summary>
        /// 开票信息新增
        /// </summary>
        /// <param name="command">实体</param>
        /// <returns>int</returns>
        [HttpPost]
        public async Task<APIResult<object>> AddAddInvoicingInfor(AddInvoicingInforCommand command)
        {
            try
            {
                logger.LogInformation(DateTime.Now + "调用开票信息新增方法成功");
            }
            catch (Exception ex)
            {
                logger.LogInformation(DateTime.Now + "调用开票信息新增方法失败" + ex.Message);
            }
            return await mediator.Send(command);
        }

        /// <summary>
        /// 开票到票新增
        /// 物联网-智能MES生产管理系统-07-开票到票管理V1.1-20250206
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> Addtickets(AddticketsCommand command)
        {
            try
            {
                logger.LogInformation(DateTime.Now + "调用开票到票新增方法成功");
            }
            catch (Exception ex)
            {
                logger.LogInformation(DateTime.Now + "调用开票到票新增方法失败" + ex.Message);
            }
            return await mediator.Send(command);
        }



        /// <summary>
        /// 开票到票采购订单新增
        /// 物联网-智能MES生产管理系统-07-开票到票管理V1.1-20250206
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> AddurchaseOrdp(AddicetsCommand command)
        {
            try
            {
                logger.LogInformation(DateTime.Now + "调用开票到票新增方法成功");
            }
            catch (Exception ex)
            {
                logger.LogInformation(DateTime.Now + "调用开票到票新增方法失败" + ex.Message);
            }
            return await mediator.Send(command);
        }



        /// <summary>
        /// 开票到票采购订单修改
        /// 物联网-智能MES生产管理系统-07-开票到票管理V1.1-20250206
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> puturchaseOrdp(updateicetsCommand command)
        {
            try
            {
                logger.LogInformation(DateTime.Now + "调用开票到票新增方法成功");
            }
            catch (Exception ex)
            {
                logger.LogInformation(DateTime.Now + "调用开票到票新增方法失败" + ex.Message);
            }
            return await mediator.Send(command);
        }
    }
}
